#include "projectdialog.h"
#include "ui_projectdialog.h"

#include <QFileDialog>

ProjectDialog::ProjectDialog(
    QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::ProjectDialog)
{
    ui->setupUi(this);
    on_leProjectName_textChanged("");
}

ProjectDialog::~ProjectDialog()
{
    delete ui;
}

Project ProjectDialog::getNewProject()
{
    ProjectDialog dlg;
    if(dlg.exec() == QDialog::Accepted) {
        return Project(dlg.getProjectDirPath(), dlg.getProjectName());
    }
    return Project();
}

QString ProjectDialog::getProjectName()
{
    return ui->leProjectName->text().trimmed();
}

QString ProjectDialog::getProjectDirPath()
{
    return ui->leProjectDirPath->text().trimmed();
}

void ProjectDialog::on_btnLoadDirPath_clicked()
{
    QString fileName = QFileDialog::getExistingDirectory(this, tr("Load dir path"), qApp->applicationDirPath());
    if(!fileName.isEmpty()) {
        ui->leProjectDirPath->setText(fileName);
    }
}


void ProjectDialog::on_buttonBox_accepted()
{

}


void ProjectDialog::on_leProjectName_textChanged(const QString &text)
{
    ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!getProjectDirPath().isEmpty() && !getProjectName().isEmpty());
}


void ProjectDialog::on_leProjectDirPath_textChanged(const QString &text)
{
    on_leProjectName_textChanged("");
}

